/**
 * Copyright 2025 Beijing Volcano Engine Technology Co., Ltd. All Rights Reserved.
 * SPDX-license-identifier: BSD-3-Clause
 */

 import { Link,useSearchParams,useNavigate } from 'react-router-dom';
import {useEffect, useState} from "react";
import { Switch, Toast } from 'react-vant';
import { getStatusSetting,setStatusSetting } from '@/api/train'
 export default function () {
    const [value,setValue]=useState<any>(0)
     useEffect(()=>{
        initStatus()
     },[])
    const initStatus=()=>{
        getStatusSetting().then(res=>{
            if(res.code===2000){
                setValue(res?.data?.participate_status)
            }
        })
    } 
    const onSwitchChange=(e:boolean)=>{
        setStatusSetting().then(res=>{
            if(res.code===2000){
                initStatus()
            }else{
                Toast.info(res.msg||'操作失败')
            }
        })
    }
     return (
        <div className="px-5 py-5 bg-white h-screen">
            <div className="border-b-[0.5px] border-solid border-[#e5e5e5 pb-5">
                <div className="text-base text-[#222222] mb-0.5">授权排行分享</div>
                <div className="flex justify-between">
                    <div className="text-sm text-[#999999]">开启后可参与排行并允许他人在排行榜中查看自己的学习记录</div>
                    <div>
                    <Switch activeColor="#FFBC0D" inactiveColor="#cccccc" size="22px" checked={value===1?true:false} onChange={e=>onSwitchChange(e)}/>
                    </div>
                </div>
            </div>
           
           
         </div>
     );
 }
